class code2 {
    //单词替换：暴力模拟startsWith
    public String replaceWords(List<String> dictionary, String sentence) {
        String[] se = sentence.split(" ");

        StringBuilder ret = new StringBuilder();

        for(String s:se) {
            String fag = s;
            for(String ss : dictionary) {
                //还需考虑最短(重复)
                if(s.startsWith(ss)) {
                    if(ss.length() < fag.length()) {
                        fag = ss;
                    }
                }
            }
            ret.append(fag).append(" ");
        }

        return ret.toString().substring(0,ret.toString().length()-1);
    }
}